/*
 * @Description:
 * @Author: 月间
 * @Date: 2024-10-14 21:07:53
 * @LastEditTime: 2024-11-07 21:04:11
 * @LastEditors:
 */
import { useAuthStore } from '@/store/modules/auth';

export function useAuth() {
  const authStore = useAuthStore();

  function hasAuth(codes: string | string[]) {
    if (!authStore.isLogin) {
      return false;
    }
    // 判断authStore.userInfo.buttons中是否出现有'*:*:*'，如果有则直接返回true
    if (authStore.userInfo.buttons.includes('*:*:*')) {
      return true;
    }
    if (typeof codes === 'string') {
      return authStore.userInfo.buttons.includes(codes);
    }

    return codes.some(code => authStore.userInfo.buttons.includes(code));
  }

  return {
    hasAuth
  };
}
